<template>
	<view class="page">
		<!---logoflex布局开始-->
		<view class="flex flex-wrap align-center justify-between benben-position-layout flex passwordLogin_flex_0" :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
			<text class='fu-iconfont2  testExamination_fd0_0_c0_c0' @tap.stop="handleJumpDiy" data-type="back" data-url="1">&#xE794;</text>
			<view class="title_text"></view>
			<view class="testExamination_fd0_0_c0_c0"></view>
		</view>
		<!---logoflex布局结束-->
		
		<view class="store_info">
			<image class="store_1" :src='STATIC_URL+"401.png"' mode=""></image>
			<view class="store_2">全渠道高效获客·全场景运营提升</view>
		</view>
		
		<!---flex布局flex布局开始-->
		<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout codeLogin_flex_1">
			<view class='flex flex-wrap align-center codeLogin_fd1_0'>
				<text class="phone_text_1">+86</text>
				<view class="phone_text_2"></view>
				<input class='flex-sub codeLogin_fd1_0_c1' type="text" placeholder="请输入账号" confirm-type="done"
					:maxlength="20" placeholder-style="color:#cccccc;font-size:30rpx" v-model="mobile" />
			</view>
			<view class='flex flex-wrap align-center codeLogin_fd1_1'>
				<!-- <input class='flex-sub codeLogin_fd1_1_c1' type="number" placeholder="请输入验证码" confirm-type="done"
					:maxlength="6" placeholder-style="color:#cccccc;font-size:30rpx" v-model="code" /> -->
				<!-- <benben-send-verification-code class='flex  codeLogin_fd1_1_c2' after-text='后重新获取' before-text='获取验证码' type='3' :phone="mobile">
				</benben-send-verification-code> -->
				<benben-flex-password-diy v-model="password"
					class-name="flex align-center flex-sub flex register_fd1_2_c1" :placeholder="'请输入密码(6~12位字母+数字)'"
					:maxlength="12" :default-type='true'
					placeholder-style="color:#cccccc;font-size:30rpx">
					<template #show>
						<text class='fu-iconfont2  register_fd1_2_c1_icon1' data-type="show">&#xE837;</text>
					</template>
					<template #hide>
						<text class='fu-iconfont2  register_fd1_2_c1_icon2' data-type="hide">&#xEBCC;</text>
					</template>
				</benben-flex-password-diy>
			</view>
			<button class='codeLogin_fd1_3 flex align-center justify-center' @tap.stop="getcodeLogin()">登录</button>
			<!-- <button class='codeLogin_fd1_4 flex align-center justify-center' @tap.stop="handleJumpDiy" data-type="back" data-url="1">微信一键登录</button> -->
		</view>
		<!---flex布局flex布局结束-->
		<view class="flex flex-wrap align-center justify-center flex passwordLogin_flex_3">
			<benben-flex-switch-new class-name='flex flex passwordLogin_fd3_0' v-model="is_tick" :disabled='false'>
				<template v-slot:checked>
		
					<view class='flex flex position-relative align-center'>
						<image class='passwordLogin_checkfd3_0_c0_c0' :src='STATIC_URL+"7.png"'>
						</image>
					</view>
				</template>
				<template v-slot:unchecked>
					<view class='flex flex position-relative justify-end align-center'>
						<image class='passwordLogin_noCheckfd3_0_c1_c0'
							:src='STATIC_URL+"8.png"'></image>
					</view>
				</template>
			</benben-flex-switch-new>
			<text class='passwordLogin_fd3_1'>请阅读并同意</text>
			<text class='passwordLogin_fd3_2' @tap.stop="handleJumpDiy" data-type="navigateTo"
				:data-url="`/pages/denglu/agreement/agreement?aid=8`">用户注册协议</text>
			<text class='passwordLogin_fd3_1'>{{$t('与')}}</text>
			<text class='passwordLogin_fd3_2' @tap.stop="handleJumpDiy" data-type="navigateTo"
				:data-url="`/pages/denglu/agreement/agreement?aid=9`">隐私协议</text>
		</view>

	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		components: {},

		data() {
			return {
				"mobile": "",  // 15137862855   15225077957
				"code": "",
				"password": "",  // admin123
				"token": "123123123123123",
				"User": {
					"userinfo": {
						"user_token": "",
						"id": "",
						"head_img": "",
						"user_name": "",
						"user_nickname": "",
						"user_email": "",
						"sex": "",
						"user_type": "",
						"mobile": "",
						"birthday": "",
						"address": "",
						"address_code": "",
						"client_id": "",
						"invite_code": "",
						"is_finger": "",
						"autograph": ""
					}
				},
				"status": 0,
				"is_tick": false,
				"is_submit": false
			};
		},
		computed: {

		},
		watch: {},
		onLoad(options) {

		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			//验证码登录
			async getcodeLogin() {
				if (this.is_submit) return;
				if (!validate(this.mobile, 'require')) {
					this.$message.info('请输入账号');
					return false;
				}
				// if (!validate(this.mobile, 'phone')) {
				// 	this.$message.info('请输入正确的手机号');
				// 	return false;
				// }
				if (!validate(this.password, 'require')) {
					this.$message.info('密码不能为空');
					return false;
				}
				if (!validate(this.password, 'password')) {
					this.$message.info('请输入密码（6~12位字母+数字）');
					return false;
				}
				if (this.is_tick === false) {
					this.$message.info('请阅读并同意用户注册协议与隐私协议');
					return false;
				}
				//请求方法
				//数据验证
				this.is_submit = true;
				let UserData = await this.$api.post(global.apiUrls.postLogin, {
					username: this.mobile,
					password: this.password
				});
				if (UserData.data.code != 1) {
					this.is_submit = false;
					this.$message.info(UserData.data.info);
					return
				}
				this.$message.info(UserData.data.info);
				let Userinfo = UserData.data;
				this.User = Userinfo.data;
				this.$store.commit('updateUserInfo', this.User);
				this.$store.commit('saveToken', this.User.token);
				uni.$emit('loginSuccess');
				setTimeout(() => {
					this.is_submit = false;
					this.$urouter.switchTab(`/pages/tabBar/index/index`);
				}, 800)
			},
			/**
			 * @event 微信登陆
			 */
			wxLogin() {
				let _this = this;
				// if (!this.check) return this.$message.info('请阅读并同意用户协议');
				// #ifdef APP-PLUS
				// 如果是app环境打开微信
				if (
					plus.runtime.isApplicationExist({
						pname: "com.tencent.mm",
						action: "weixin://",
					})
				) {
					uni.getProvider({
						service: "oauth",
						success: function(res) {
							console.log(res);
							// 如果支持微信等，就执行 wx_login_fn 方法
							if (~res.provider.indexOf("weixin")) {
								_this.wx_login_fn();
							}
						},
						fail: function(err) {
							// api错误是打印错误
							console.log(err);
						},
					});
				} else {
					// 调起失败时提醒用户
					this.$message.info("请安装微信后再使用此功能");
				}
				// #endif
			},
			/**
			 * @function 微信授权登录
			 */
			wx_login_fn() {
				let _this = this;
				/**
				 * @desc uniapp的登陆api
				 * @param {String} provider - 登录服务提供商
				 * @param {login~success} loginRes - 接口调用成功时的回调函数
				 */
				uni.login({
					provider: "weixin",
					// onlyAuthorize: true, // 微信登录仅请求授权认证
					/**
					 * @callback login~success
					 * @param {Object} loginRes - api返回来的信息
					 */
					success: function(loginRes) {
						console.log(loginRes);
						/**
						 * @desc 获取用户信息
						 * @param {String} provider - 登录服务提供商
						 * @param {Funtion} success - 接口调用成功时的回调函数
						 */
						uni.getUserInfo({
							provider: "weixin",
							/**
							 * @callback success
							 * @param {Object} infoRes - api返回来的信息
							 */
							success: function(infoRes) {
								// 显示加载状态
								uni.showLoading({
									title: '加载中...',
								});
								/**
								 * @let {String} nickName - 结构出来的变量昵称
								 * @let {String} avatarUrl - 解构出来的头像链接
								 * @let {String} gender - 结构出来的性别
								 */
								let {
									nickName,
									avatarUrl,
									gender
								} = infoRes.userInfo;
								// #ifdef APP-PLUS
								let client_id = "client_id";
								//  @const {Number} appSystem - 判断设备类型 1：ios；2：安卓；
								let appSystem = uni.getSystemInfoSync().platform == "ios" ? 1 : 2;
								/**
								 * @description 第三方登录请求接口
								 */
								_this.$api
									.post(global.apiUrls.post5d7660a421e69, {
										type: 1,
										wx_unionid: infoRes.userInfo.unionId,
										qq_unionid: "",
										wb_unionid: "",
										client_id: client_id || "",
										appSystem: appSystem || "",
										nickname: nickName,
										avatar: avatarUrl,
										gender: gender,
									})
									.then((res) => {
										console.log(res);
										// 保存用户信息
										global.tempUserLoginInfo = infoRes.userInfo;
										// 关闭加载效果
										uni.hideLoading();
										if (res.data.code == 1) {
											_this.$message.info(res.data.msg);
											/**
											 * @description 向Vux发送用户信息保存
											 * @param {String} updateUserInfo - 调用的方法名称
											 * @param {Object} res.data.data.userinfo - 用户信息
											 */
											_this.$store.commit(
												"updateUserInfo",
												res.data.data.userinfo
											);
											global.token = res.data.data.userinfo.user_token;
											uni.setStorageSync('USER_TOKEN', res.data.data.userinfo.user_token);
											setTimeout(() => {
												uni.switchTab({
													url: '/pages/tabBar/index/index'
												})
											}, 800);
										} else if (res.data.code == -999) {
											/**
											 * @description 清除当前页面，跳转到绑定手机页面
											 */
											_this.$urouter.redirectTo({
												url: "/pages/denglu/bindingPhone/bindingPhone",
												params: {
													unionId: infoRes.userInfo.unionId,
													openId: infoRes.userInfo.openId,
													sex: infoRes.userInfo.gender,
													nickName: infoRes.userInfo
														.nickName,
													avatarUrl: infoRes.userInfo
														.avatarUrl,
													authType: "wx_unionid",
												},
											});
											// 点击手机号账号登录按钮
										} else if (res.code == -1) {
											_this.$message.info(res.data.msg);
											return;
										}
									})
									.catch((err) => {
										uni.hideLoading();
										console.log(err);
									});
								// #endif
								console.log(infoRes.userInfo.unionId, "app微信登录");
			
							},
							fail: function(err) {
								uni.hideLoading();
								console.log(err);
							}
						});
					},
					fail: function(err) {
						uni.hideLoading();
						console.log(err);
					},
				});
			},
		}
	};
</script>
<style lang="scss" scoped>
	.phone_text_1 {
		font-weight: 500;
		font-size: 30rpx;
		color: #000000;
	}
	.phone_text_2 {
		margin: 0 22rpx;
		width: 2rpx;
		height: 26rpx;
		background: #EFEFEF;
	}
	.store_info {
		padding-left: 56rpx;
		margin-top: 74rpx;
		.store_1 {
			width: 344rpx;
			height: 58rpx;
		}
		.store_2 {
			margin-top: 8rpx;
			font-weight: 400;
			font-size: 28rpx;
			color: #FFFFFF;
		}
	}
	::v-deep .register_fd1_2_c1 {
		font-size: 30rpx;
		color: #333;
		font-weight: 400;
		width: 570rpx;
	}
	
	.register_fd1_2_c1_icon1 {
		text-align: center;
		font-size: 34rpx;
		font-weight: 600;
	}
	
	.register_fd1_2_c1_icon2 {
		text-align: center;
		font-size: 40rpx;
	}
	.codeLogin_fd2_0_c0 {
		background: rgba(238, 238, 238, 1);
		background-size: 100% !important;
		background-size: 100% auto !important;
		height: 1rpx;
		width: 157rpx;
	}

	.codeLogin_fd2_0_c1 {
		line-height: 32rpx;
		font-size: 26rpx;
		font-weight: 400;
		color: rgba(153, 153, 153, 1);
		padding: 0rpx 7rpx 0rpx 7rpx;
	}

	.codeLogin_fd2_0_c2 {
		background: rgba(238, 238, 238, 1);
		background-size: 100% !important;
		background-size: 100% auto !important;
		height: 1rpx;
		width: 157rpx;
	}

	.codeLogin_fd2_1 {
		width: 48rpx;
		height: 48rpx;
		margin: 40rpx 0rpx 0rpx 0rpx;
	}

	.codeLogin_flex_2 {
		background: #fff;
		background-size: 100% !important;
		width: 750rpx;
		height: 237rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
		background-size: 100% auto !important;
	}

	.codeLogin_fd1_0 {
		height: 96rpx;
		background: #F6F7FB;
		border-radius: 16rpx;
		padding: 0 30rpx;
	}

	.codeLogin_fd1_0_c0 {
		width: 34rpx;
		height: 34rpx;
		margin: 0rpx 28rpx 0rpx 0rpx;
	}

	.codeLogin_fd1_0_c1 {
		font-size: 30rpx;
		font-weight: 400;
		color: #111;
	}

	.codeLogin_fd1_1 {
		height: 96rpx;
		margin-top: 20rpx;
		padding: 0 30rpx;
		background: #F6F7FB;
		border-radius: 16rpx;
	}

	.codeLogin_fd1_1_c0 {
		width: 34rpx;
		height: 34rpx;
		margin: 0rpx 28rpx 0rpx 0rpx;
	}

	.codeLogin_fd1_1_c1 {
		font-size: 30rpx;
		font-weight: 400;
		color: #111;
	}

	.codeLogin_fd1_1_c2 {
		font-weight: 500;
		font-size: 30rpx;
		color: #1A66FA;
	}

	.codeLogin_fd1_2 {
		line-height: 40rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
		margin: 32rpx 0rpx 48rpx 0rpx;
	}

	.codeLogin_fd1_3 {
		width: 642rpx;
		height: 96rpx;
		background: #1A66FA;
		border-radius: 16rpx;
		font-weight: 500;
		font-size: 30rpx;
		color: #FFFFFF;
		margin-top: 80rpx;
	}
	.codeLogin_fd1_4 {
		width: 642rpx;
		height: 96rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		border: 2rpx solid #EEEEEE;
		font-weight: 500;
		font-size: 30rpx;
		color: #222222;
	}

	.codeLogin_fd1_4 {
		line-height: 40rpx;
		margin: 32rpx 0rpx 0rpx 0rpx;
	}

	.codeLogin_fd1_4_c0 {
		font-size: 28rpx;
		font-weight: 400;
		color: #999999;
	}

	.codeLogin_fd1_4_c1 {
		background: rgba(153, 153, 153, 1);
		background-size: 100% !important;
		width: 1rpx;
		height: 24rpx;
		background-size: 100% auto !important;
		margin: 0rpx 32rpx 0rpx 32rpx;
	}

	.codeLogin_fd1_4_c2 {
		font-size: 28rpx;
		font-weight: 400;
		color: #999999;
	}

	.codeLogin_flex_1 {
		padding: 58rpx 54rpx 0rpx 54rpx;
		background: #fff;
		border-radius: 32rpx 32rpx 0 0;
		margin-top: 120rpx;
	}

	.codeLogin_fd0_0 {
		background: transparent;
		background-size: 100% !important;
		width: 180rpx;
		height: 180rpx;
		border-radius: 48rpx 48rpx 48rpx 48rpx;
		background-size: 100% auto !important;
	}

	.codeLogin_flex_0 {
		padding: 110rpx 0rpx 80rpx 0rpx;
	}

	.page {
		min-height: calc(100vh - var(--window-bottom));
		background: url(https://speed.zhongchuxing.com/gjdimages/402.png) no-repeat, #fff;
		background-size: 100% auto !important;
	}
	.passwordLogin_flex_0 {
		width: 750rpx;
		height: 88rpx;
		position: relative;
		z-index: 10;
		padding: 0 32rpx;
	}
	.testExamination_fd0_0_c0_c0 {
		font-size: 32rpx;
		font-weight: 500;
		color: #fff;
	}
	.passwordLogin_flex_3 {
		margin-top: 48rpx;
	}
	
	.passwordLogin_fd3_2 {
		font-weight: 500;
		font-size: 24rpx;
		color: #222222;
		text-decoration: underline;
		margin: 0 5rpx;
	}
	
	.passwordLogin_fd3_1 {
		font-size: 24rpx;
		font-weight: 400;
		color: #666666;
	}
	
	.passwordLogin_noCheckfd3_0_c1_c0 {
		width: 32rpx;
		height: 32rpx;
		margin: 6rpx 0rpx 0rpx 0rpx;
	}
	
	.passwordLogin_checkfd3_0_c0_c0 {
		width: 32rpx;
		height: 32rpx;
		margin: 6rpx 0rpx 0rpx 0rpx;
	}
	
	::v-deep .passwordLogin_fd3_0 {
		margin: 0rpx 16rpx 0rpx 0rpx;
		transform: translateY(-3rpx);
	}
</style>
